package com.ruoyi.service;

import com.ruoyi.entity.BizReserveOrder;
import com.ruoyi.mapper.BizReserveOrderMapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import com.ruoyi.bean.BizReserveOrderFrom;
import com.sxftech.resp.ResponseData;
/**
 * <p>
 * 预约子订单 服务实现类
 * </p>
 *
 * @author liuxing
 * @since 2020-10-29
 */
@Service
public class BizReserveOrderService extends ServiceImpl<BizReserveOrderMapper, BizReserveOrder> {

	public ResponseData create(BizReserveOrderFrom bizReserveOrder) {
		BizReserveOrder entity = transformationFrom(bizReserveOrder);
		this.save(entity);
		return ResponseData.success("新增成功");
	}
	
	public ResponseData modify(BizReserveOrderFrom bizReserveOrder) {
		if(findById(bizReserveOrder.getId())== null) {
			return ResponseData.fail("没有找到对应记录");
		}
		BizReserveOrder entity = transformationFrom(bizReserveOrder);
		entity.setId(bizReserveOrder.getId());
		this.updateById(entity);
		return ResponseData.success("修改成功");
	}

	public BizReserveOrder transformationFrom(BizReserveOrderFrom bizReserveOrder) {
		BizReserveOrder entity = new BizReserveOrder();
		entity.setOrderId(bizReserveOrder.getOrderId());
		entity.setParkingLot(bizReserveOrder.getParkingLot());
		entity.setParkingLotCode(bizReserveOrder.getParkingLotCode());
		entity.setPlAddress(bizReserveOrder.getPlAddress());
		entity.setParkingSpace(bizReserveOrder.getParkingSpace());
		entity.setParkingSpaceId(bizReserveOrder.getParkingSpaceId());
		entity.setPlateNumber(bizReserveOrder.getPlateNumber());
		entity.setReserveMinutes(bizReserveOrder.getReserveMinutes());
		entity.setParkingTime(bizReserveOrder.getParkingTime());
		entity.setEnterTime(bizReserveOrder.getEnterTime());
		entity.setLeaveTime(bizReserveOrder.getLeaveTime());
		entity.setPriceSystemCode(bizReserveOrder.getPriceSystemCode());
		entity.setSpaceProperty(bizReserveOrder.getSpaceProperty());
		entity.setExpiryDate(bizReserveOrder.getExpiryDate());
		entity.setSpaceOwnerMobile(bizReserveOrder.getSpaceOwnerMobile());
		entity.setOvertimeRemark(bizReserveOrder.getOvertimeRemark());
		entity.setChargeGate(bizReserveOrder.getChargeGate());
		entity.setLocalId(bizReserveOrder.getLocalId());
		entity.setDiscount(bizReserveOrder.getDiscount());
		entity.setSpaceType(bizReserveOrder.getSpaceType());
		entity.setCreateTime(bizReserveOrder.getCreateTime());
		entity.setModifyTime(bizReserveOrder.getModifyTime());
		return entity;
	}

	public BizReserveOrderFrom transformationBean(BizReserveOrder bizReserveOrder) {
		BizReserveOrderFrom from = new BizReserveOrderFrom();
		from.setOrderId(bizReserveOrder.getOrderId());
		from.setParkingLot(bizReserveOrder.getParkingLot());
		from.setParkingLotCode(bizReserveOrder.getParkingLotCode());
		from.setPlAddress(bizReserveOrder.getPlAddress());
		from.setParkingSpace(bizReserveOrder.getParkingSpace());
		from.setParkingSpaceId(bizReserveOrder.getParkingSpaceId());
		from.setPlateNumber(bizReserveOrder.getPlateNumber());
		from.setReserveMinutes(bizReserveOrder.getReserveMinutes());
		from.setParkingTime(bizReserveOrder.getParkingTime());
		from.setEnterTime(bizReserveOrder.getEnterTime());
		from.setLeaveTime(bizReserveOrder.getLeaveTime());
		from.setPriceSystemCode(bizReserveOrder.getPriceSystemCode());
		from.setSpaceProperty(bizReserveOrder.getSpaceProperty());
		from.setExpiryDate(bizReserveOrder.getExpiryDate());
		from.setSpaceOwnerMobile(bizReserveOrder.getSpaceOwnerMobile());
		from.setOvertimeRemark(bizReserveOrder.getOvertimeRemark());
		from.setChargeGate(bizReserveOrder.getChargeGate());
		from.setLocalId(bizReserveOrder.getLocalId());
		from.setDiscount(bizReserveOrder.getDiscount());
		from.setSpaceType(bizReserveOrder.getSpaceType());
		from.setCreateTime(bizReserveOrder.getCreateTime());
		from.setModifyTime(bizReserveOrder.getModifyTime());

		return from;
	}

	
	public BizReserveOrderFrom findById(String id) {
		BizReserveOrder entity = this.getOne(new QueryWrapper<BizReserveOrder>().lambda()
				.eq(BizReserveOrder::getId, id)
				);
		if(entity == null) return null;
		return transformationBean(entity);
	}
	
	public ResponseData remove(String id) {
		if(findById(id)== null) {
			return ResponseData.fail("没有找到对应记录");
		}
		BizReserveOrder bizReserveOrder = new BizReserveOrder();
		bizReserveOrder.setId(id);
		this.updateById(bizReserveOrder);
		return ResponseData.success("删除成功");
	}
	
	public IPage pageList(Integer page, Integer size, BizReserveOrderFrom ibean) {
		return this.page(new Page(page, size), new QueryWrapper<BizReserveOrder>().lambda()
				.eq(ibean.getOrderId() != null, BizReserveOrder::getOrderId, ibean.getOrderId())
				.eq(StringUtils.isNotEmpty(ibean.getParkingLot()), BizReserveOrder::getParkingLot, ibean.getParkingLot())
				.eq(StringUtils.isNotEmpty(ibean.getParkingLotCode()), BizReserveOrder::getParkingLotCode, ibean.getParkingLotCode())
				.eq(StringUtils.isNotEmpty(ibean.getPlAddress()), BizReserveOrder::getPlAddress, ibean.getPlAddress())
				.eq(StringUtils.isNotEmpty(ibean.getParkingSpace()), BizReserveOrder::getParkingSpace, ibean.getParkingSpace())
				.eq(ibean.getParkingSpaceId() != null, BizReserveOrder::getParkingSpaceId, ibean.getParkingSpaceId())
				.eq(StringUtils.isNotEmpty(ibean.getPlateNumber()), BizReserveOrder::getPlateNumber, ibean.getPlateNumber())
				.eq(ibean.getReserveMinutes() != null, BizReserveOrder::getReserveMinutes, ibean.getReserveMinutes())
				.eq(ibean.getParkingTime() != null, BizReserveOrder::getParkingTime, ibean.getParkingTime())
				.eq(ibean.getEnterTime() != null, BizReserveOrder::getEnterTime, ibean.getEnterTime())
				.eq(ibean.getLeaveTime() != null, BizReserveOrder::getLeaveTime, ibean.getLeaveTime())
				.eq(StringUtils.isNotEmpty(ibean.getPriceSystemCode()), BizReserveOrder::getPriceSystemCode, ibean.getPriceSystemCode())
				.eq(StringUtils.isNotEmpty(ibean.getSpaceProperty()), BizReserveOrder::getSpaceProperty, ibean.getSpaceProperty())
				.eq(ibean.getExpiryDate() != null, BizReserveOrder::getExpiryDate, ibean.getExpiryDate())
				.eq(StringUtils.isNotEmpty(ibean.getSpaceOwnerMobile()), BizReserveOrder::getSpaceOwnerMobile, ibean.getSpaceOwnerMobile())
				.eq(StringUtils.isNotEmpty(ibean.getOvertimeRemark()), BizReserveOrder::getOvertimeRemark, ibean.getOvertimeRemark())
				.eq(ibean.getChargeGate() != null, BizReserveOrder::getChargeGate, ibean.getChargeGate())
				.eq(StringUtils.isNotEmpty(ibean.getLocalId()), BizReserveOrder::getLocalId, ibean.getLocalId())
				.eq(ibean.getDiscount() != null, BizReserveOrder::getDiscount, ibean.getDiscount())
				.eq(StringUtils.isNotEmpty(ibean.getSpaceType()), BizReserveOrder::getSpaceType, ibean.getSpaceType())
				.eq(ibean.getCreateTime() != null, BizReserveOrder::getCreateTime, ibean.getCreateTime())
				.eq(ibean.getModifyTime() != null, BizReserveOrder::getModifyTime, ibean.getModifyTime())
				);
	}
}
